package clienteServidor.mensajeDatagrama;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

class Serializador {
	
	public static byte[] leerObjeto(Object o) throws IOException{
		ByteArrayOutputStream bs= new ByteArrayOutputStream();
		ObjectOutputStream os = new ObjectOutputStream (bs);
		os.writeObject(o);
		os.close();
		return bs.toByteArray();
	}
		 
	public static Object escribirObjeto(byte[] bytes)  throws IOException, ClassNotFoundException{
		ByteArrayInputStream bs= new ByteArrayInputStream(bytes);
		ObjectInputStream is = new ObjectInputStream(bs);
		Object unObjetoSerializable = is.readObject();
		is.close();
		return unObjetoSerializable;
	}

}
